using System;

namespace CodeLines.CodeIgnoreRules
{
    internal class Contain : ICodeIgnoreRule
    {
        private string _rule;

        public bool SetRule(string rule)
        {
            if (rule.Length <= 2 || !rule.StartsWith("*") || !rule.EndsWith("*")) return false;
            _rule = rule.Substring(1, rule.Length - 2);
            return true;

        }

        public bool IsIgnore(string code)
        {
            if (string.IsNullOrWhiteSpace(code)) return true;
            return code.Contains(_rule, StringComparison.OrdinalIgnoreCase);
        }

        public override string ToString()
        {
            return $"Contain {_rule}";
        }
    }
}
